'use strict';
var base64_url_decode = require('./base64_url_decode');
module.exports =  (token,options) => {
  if (typeof token !== 'string') {
    throw new Error('Invalid token specified');
  }

  options = options || {};
  var pos = options.header === true ? 0 : 1;
  try {
    return JSON.parse(base64_url_decode(token.split('.')[pos]));
  } catch (e) {
    throw  new Error ('Invalid token specified: ' + e.message);
  }
};


